package com.sanweibook.jhook.biz.aop;

import com.sanweibook.jhook.dal.datasource.DataSourceEnum;
import com.sanweibook.jhook.dal.datasource.DynamicDataSourceHolder;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * Created by twg on 2017/5/11.
 */
@Aspect
@Component
public class DataSourceAspect {
    @Pointcut("execution( * com.sanweibook.jhook.biz..*.get*(..)) || execution(* com.sanweibook.jhook.biz..*.query*(..))")
    private void dataSourceSlave(){};

    @Before("dataSourceSlave()")
    public void before(JoinPoint joinPoint) throws Throwable {
        DynamicDataSourceHolder.setDataSource(DataSourceEnum.SLAVE.name());
    }
}
